package com.ruoyi.asset.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.AstTaskUser;
import com.ruoyi.asset.service.IAstTaskUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务分配Controller
 * 
 * @author xunzhe
 * @date 2024-06-21
 */
@Controller
@RequestMapping("/asset/taskUser")
public class AstTaskUserController extends BaseController
{
    private String prefix = "asset/taskUser";

    @Autowired
    private IAstTaskUserService astTaskUserService;

    @RequiresPermissions("asset:taskUser:view")
    @GetMapping()
    public String taskUser()
    {
        return prefix + "/taskUser";
    }

    /**
     * 查询任务分配列表
     */
    @RequiresPermissions("asset:taskUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AstTaskUser astTaskUser)
    {
        startPage();
        List<AstTaskUser> list = astTaskUserService.selectAstTaskUserList(astTaskUser);
        return getDataTable(list);
    }

    /**
     * 导出任务分配列表
     */
    @RequiresPermissions("asset:taskUser:export")
    @Log(title = "任务分配", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AstTaskUser astTaskUser)
    {
        List<AstTaskUser> list = astTaskUserService.selectAstTaskUserList(astTaskUser);
        ExcelUtil<AstTaskUser> util = new ExcelUtil<AstTaskUser>(AstTaskUser.class);
        return util.exportExcel(list, "任务分配数据");
    }

    /**
     * 新增任务分配
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存任务分配
     */
    @RequiresPermissions("asset:taskUser:add")
    @Log(title = "任务分配", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AstTaskUser astTaskUser)
    {
        return toAjax(astTaskUserService.insertAstTaskUser(astTaskUser));
    }

    /**
     * 修改任务分配
     */
    @RequiresPermissions("asset:taskUser:edit")
    @GetMapping("/edit/{assignmentId}")
    public String edit(@PathVariable("assignmentId") Long assignmentId, ModelMap mmap)
    {
        AstTaskUser astTaskUser = astTaskUserService.selectAstTaskUserByAssignmentId(assignmentId);
        mmap.put("astTaskUser", astTaskUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存任务分配
     */
    @RequiresPermissions("asset:taskUser:edit")
    @Log(title = "任务分配", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AstTaskUser astTaskUser)
    {
        return toAjax(astTaskUserService.updateAstTaskUser(astTaskUser));
    }

    /**
     * 删除任务分配
     */
    @RequiresPermissions("asset:taskUser:remove")
    @Log(title = "任务分配", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(astTaskUserService.deleteAstTaskUserByAssignmentIds(ids));
    }
}
